onpagehide
event in JavaScript?onpagehide
event triggers. The visitor can move to another page or click a link after leaving the current web page. An example here displays an alert box when the user tries to leave the page. This happens since onpagehide
event fires when the page is left : <!DOCTYPE html>
<html>
<body onpagehide="display()">
<p>Close the page</p>
<script>
function display() {
alert("It was nice having you here!");
}
</script>
</body>
</html>